﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public DataSet QueryGPDAT(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;
            // GSCMANDANT GSCART GSCVAR GSCFARBE


            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM GPDAT WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM GPDAT WHERE  "
                    + "  GPMANDANT=:GPMANDANT AND GPPARTIE=:GPPARTIE";
                    or1.Parameters.Add("GPMANDANT", OracleType.NVarChar).Value = dwData["GPMANDANT"].ToString();
                    or1.Parameters.Add("GPPARTIE", OracleType.NVarChar).Value = dwData["GPPARTIE"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM GPDAT WHERE  "
                        + "  GPMANDANT=:GPMANDANT AND GPPARTIE=:GPPARTIE";
                    or1.Parameters.Add("GPMANDANT", OracleType.NVarChar).Value = dwData["GPMANDANT"].ToString();
                    or1.Parameters.Add("GPPARTIE", OracleType.NVarChar).Value = dwData["GPPARTIE"].ToString();
                    break;
                case 4:
                    or1.CommandText = "SELECT DISTINCT GP.* FROM ZUTEI RIGHT JOIN GPDAT GP ON ZUMANDANT=GPMANDANT AND ZUPARTIE=GPPARTIE"
                    + " WHERE  ZUMANDANT=:ZUMANDANT AND ZUAUFKRS=:ZUAUFKRS AND ZUAUFLFD=:ZUAUFLFD"; ;
                    or1.Parameters.Add("ZUMANDANT", OracleType.NVarChar).Value = dwData["ZUMANDANT"].ToString();
                    or1.Parameters.Add("ZUAUFKRS", OracleType.NVarChar).Value = dwData["ZUAUFKRS"].ToString();
                    or1.Parameters.Add("ZUAUFLFD", OracleType.NVarChar).Value = dwData["ZUAUFLFD"].ToString();
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "GPDAT";
            }
            setReturn.Merge(Result);
            return setReturn;
        }
        public void UpdateGPDAT(DataRow dwData, int option = 1)
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {                
                case 1:
                    or1 = OracleDB.CreateCommand();
                    or1.CommandText = "UPDATE GPDAT SET "
                        + "GPFBPART=:GPFBPART "
                        + " WHERE GPMANDANT=:GPMANDANT AND GPPARTIE = :GPPARTIE AND GPPARTIEKZ = :GPPARTIEKZ ";
                    or1.Parameters.Add("GPMANDANT", OracleType.NVarChar).Value = dwData["ZUMANDANT"].ToString();
                    or1.Parameters.Add("GPPARTIE", OracleType.NVarChar).Value = dwData["ZUPARTIE"].ToString();
                    or1.Parameters.Add("GPPARTIEKZ", OracleType.NVarChar).Value = dwData["ZUPARTIEKZ"].ToString();
                    or1.Parameters.Add("GPFBPART", OracleType.NVarChar).Value = dwData["ZUSPPART"].ToString();
                    break;

            }
            Connect2Proxy(or1);
        }
    }
}
